﻿@model ActivityLogSearchModel
@inject AdminAreaSettings adminAreaSettings
@{
    //page title
    ViewBag.Title = T("Admin.Configuration.ActivityLog.ActivityLog").Text;
}

<div class="row">
    <div class="col-md-12">
        <div class="x_panel light form-fit">
            <div class="x_title">
                <div class="caption">
                    <i class="fa fa-sitemap"></i>
                    @T("Admin.Configuration.ActivityLog.ActivityLog")
                </div>
                <div class="actions btn-group btn-group-devided">
                    <a asp-action="ClearAll" class="btn red" onclick="return confirm('@T("Admin.Common.AreYouSure")');">
                        <i class="fa fa-trash-o"></i>
                        @T("Admin.Common.Clear")
                    </a>
                    <vc:admin-widget widget-zone="activity_log_list_buttons" additional-data="null" />
                </div>
            </div>
            <div class="x_content form">
                <div class="form-horizontal">
                    <div class="form-body">
                        <div class="form-group">
                            <admin-label asp-for="Comment" />
                            <div class="col-md-4 col-sm-6">
                                <admin-input asp-for="Comment" />
                            </div>
                        </div>
                        <div class="form-group">
                            <admin-label asp-for="CreatedOnFrom" />
                            <div class="col-md-4 col-sm-6">
                                <admin-input asp-for="CreatedOnFrom" />
                            </div>
                        </div>
                        <div class="form-group">
                            <admin-label asp-for="CreatedOnTo" />
                            <div class="col-md-4 col-sm-6">
                                <admin-input asp-for="CreatedOnTo" />
                            </div>
                        </div>
                        <div class="form-group">
                            <admin-label asp-for="IpAddress" />
                            <div class="col-md-4 col-sm-6">
                                <admin-input asp-for="IpAddress" />
                            </div>
                        </div>
                        <div class="form-group">
                            <admin-label asp-for="ActivityLogTypeId" />
                            <div class="col-md-4 col-sm-6">
                                <admin-select asp-for="ActivityLogTypeId" asp-items="Model.ActivityLogType" />
                            </div>
                        </div>
                    </div>
                    <div class="form-actions">
                        <div class="row">
                            <div class="offset-md-3 offset-sm-3 col-md-9 col-sm-9">
                                <button class="btn btn-success filter-submit" id="search-log">
                                    <i class="fa fa-search"></i> @T("Admin.Common.Search")
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="x_content">
                <div id="activityLog-grid"></div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        $("#activityLog-grid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("ListLogs", "ActivityLog"))",
                        type: "POST",
                        dataType: "json",
                        data: additionalData
                    },
                    destroy: {
                        url: "@Html.Raw(Url.Action("ActivityLogDelete", "ActivityLog"))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    }
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors",
                    model: {
                        id: "Id",
                        fields: {
                            //do not implicitly specify all fields
                            //we do it only for fields which implicitly require it
                            //otherwise, they'll be formatted wrong way
                            CreatedOn: {type: "date" }
                        }
                    }
                },
                error: function(e) {
                    display_kendoui_grid_error(e);
                    // Cancel the changes
                    this.cancelChanges();
                },
                pageSize: @(adminAreaSettings.DefaultGridPageSize),
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true
            },
            pageable: {
                refresh: true,
                pageSizes: [@(adminAreaSettings.GridPageSizes)]
            },
            editable: {
                confirmation: false,
                mode: "inline"
            },
            scrollable: false,
            columns: [{
                field: "ActivityLogTypeName",
                title: "@T("Admin.Configuration.ActivityLog.ActivityLog.Fields.ActivityLogType")",
                width: 150
            }, {
                field: "CustomerId",
                title: "@T("Admin.Configuration.ActivityLog.ActivityLog.Fields.Customer")",
                width: 100,
                template: '<a href="@Url.Action("Edit", "Customer")/#=CustomerId#">#:CustomerEmail#</a>'
            }, {
                field: "IpAddress",
                title: "@T("Admin.Configuration.ActivityLog.ActivityLog.Fields.IpAddress")"
            }, {
                field: "Comment",
                title: "@T("Admin.Configuration.ActivityLog.ActivityLog.Fields.Comment")"
            }, {
                field: "CreatedOn",
                title: "@T("Admin.System.Log.Fields.CreatedOn")",
                width: 200,
                type: "date",
                format: "{0:G}"
            }, {
                command: { name: "destroy", text: "@T("Admin.Common.Delete")" },
                title: "@T("Admin.Common.Delete")",
                width: 100
            }]
        });
    });
</script>
<script>

    $(document).ready(function () {

        $('#search-log').click(function () {
            var grid = $('#activityLog-grid').data('kendoGrid');
            grid.dataSource.page(1); //new search. Set page size to 1
            //grid.dataSource.read(); we already loaded the grid above using "page" function
            return false;
        });
    });

    function additionalData() {
        var data = {
            Comment: $('#@Html.FieldIdFor(model => model.Comment)').val(),
            CreatedOnFrom: $('#@Html.FieldIdFor(model => model.CreatedOnFrom)').val(),
            CreatedOnTo: $('#@Html.FieldIdFor(model => model.CreatedOnTo)').val(),
            IpAddress: $('#@Html.FieldIdFor(model => model.IpAddress)').val(),
            ActivityLogTypeId: $('#ActivityLogTypeId').val()
        };
        addAntiForgeryToken(data);
        return data;
    }
</script>
